﻿using System;
using System.Collections.Generic;
using System.Linq;
using SuppKids.Core;
using SuppKids.Core.Domain;

namespace SuppKids.ViewModels.MenuRaskladka
{
	public class GroupsViewModel : ViewModelBase
	{
		public Group Group { get; set; }

		public GroupsViewModel(Group @group)
		{
			Group = @group;
		}

		public int GroupId
		{
			get
			{
				return this.Group.Id;
			}
		}

		public string GroupName
		{
			get
			{
				return this.Group.Name;
			}
		}

		private Dictionary<MealType, uint> childrenCount;
		public Dictionary<MealType, uint> ChildrenCount
		{
			get
			{
				if (this.childrenCount == null)
				{
					this.childrenCount = new Dictionary<MealType, uint>();
					foreach (var mealType in Enum.GetValues(typeof(MealType)).Cast<MealType>())
					{
						this.childrenCount.Add(mealType, 0);
					}
				}

				return this.childrenCount;
			}
			set
			{
				this.childrenCount = value;
				this.OnPropertyChanged(Lambda.Property<GroupsViewModel>(x => x.ChildrenCount));
			}
		}

		public bool IsUsed
		{
			get { return this.ChildrenCount.Any(a => a.Value > 0); }
		}

		public override bool AllFieldsIsNotEmpty
		{
			get
			{
				return !string.IsNullOrWhiteSpace(this.GroupName);
			}
		}
	}
}